***Nature Energy Regressions***
** EI Survey -- Wave 1 (May 2020)
** Original data cleaned in separate do file ("Cleaning_Replication.do")
clear

use ${ai}/replication_survey.dta
capture log close
log using ${ac}\replication, replace text

svyset newid [pweight=weight]

***Make Notice binary***
gen notice_year_binary=0 if notice_year==0
replace notice_year_binary=1 if notice_year>0

***Make Disconnect binary**
gen disconnect_year_binary=0 if disconnect_year==0
replace disconnect_year_binary=1 if disconnect_year>0


***Year but not one month***
gen hhbill_justyear=0
replace hhbill_justyear=1 if hhbill_year==1 & hhbill_month !=1

gen notice_justyear=0
replace notice_justyear=1 if notice_year_binary==1 & notice_month !=1 

gen disconnect_justyear=0
replace disconnect_justyear=1 if disconnect_year_binary==1 & disconnect_month !=1 

**Create COVID binaries**
gen covid_rentstruggles=0
replace covid_rentstruggles=1 if covid_rent > 3
gen covid_foodstruggles=0
replace covid_foodstruggles=1 if covid_feedfamily > 3
gen covid_medicalstruggles=0
replace covid_medicalstruggles=1 if covid_medicalcare > 3

replace covid_lostjobhours=0 if covid_lostjobhours !=1
label define covid_lostjobhours_label 0 "no" 1 "yes"
label values covid_lostjobhours covid_lostjobhours_label

label define covid_rentstruggles_label 0 "no" 1 "yes"
label values covid_rentstruggles covid_rentstruggles_label

label define covid_foodstruggles_label 0 "no" 1 "yes"
label values covid_foodstruggles covid_foodstruggles_label

label define covid_medicalstruggles_label 0 "no" 1 "yes"
label values covid_medicalstruggles covid_medicalstruggles_label

replace hh_under5=1 if hh_under5>0
replace hh_disability=1 if hh_disability>0

gen over_150_fpl=0
replace over_150_fpl=1 if fpl==3

gen between_100_150_fpl=0
replace between_100_150_fpl=1 if fpl==2

gen govassist_yr_binary=0
replace govassist_yr_binary=1 if gov_assistance_year>0
gen govassist_mo_binary=0
replace govassist_mo_binary=1 if gov_assistance_month>0

replace dwelling_condition=1 if dwelling_condition>0
rename dwelling_condition housing_conditions

gen home=0
replace home=1 if dwelling_type==2 | dwelling_type==3 | dwelling_type==4


gen mobile=0
replace mobile=1 if dwelling_type==1

gen apartment=0
replace apartment=1 if dwelling_type==2

gen attached_home=0
replace attached_home=1 if dwelling_type==3

xi i.inputstate


****Demographics regressions year vs month****
global demographics "hh_under5 hh_disability unemployed electronic_device retired black hispanic other female age under_100_fpl between_100_150_fpl educ mobile apartment attached_home housing_conditions pcturban"

logit hhbill_year $demographics govassist_yr_binary  _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) asis
est store a

logit notice_year_binary $demographics govassist_yr_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) asis
est store b

logit disconnect_year_binary $demographics govassist_yr_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) asis
est store c

logit hhbill_month $demographics govassist_mo_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) asis
est store d

logit notice_month $demographics govassist_mo_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) asis
est store e

logit disconnect_month $demographics govassist_mo_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) asis
est store f


la var hh_disability "Disability"
la var housing_conditions "Poor HH Conditions"
la var govassist_mo_binary "Gov Assist"
la var govassist_yr_binary "Gov Assist"
la var hh_under5 "Children Under 5"
la var electronic_device "Electronic Device"
la var black "Black"
la var hispanic "Hispanic"
la var retired "Retired"
la var under_100_fpl "Under 100% FPL"


set scheme s1color
coefplot (a, label (Household Bill) msymbol(O)) (b, label (Received Notice) msymbol(T)) (c, label (Got Disconnected) msymbol(S)), bylabel("Last Year") || (d, label (Household Bill) msymbol(O)) (e, label (Received Notice) msymbol(T)) (f, label (Got Disconnected) msymbol(S)), bylabel("Last Month") eform drop(_cons) xline(1) xtitle("Odds ratio") text(1.1 1.2, box fcolor(white) lcolor(black)) ysize (12) xsize (13) legend(pos(5) row(1)) keep(hh_under5 electronic_device retired black hispanic housing_conditions under_100_fpl) graphregion(fcolor(white)) xlabel(0(1)8)




****Demographics + Assistance + COVID month***
***Factor COVID***
alpha covid_rent covid_forego covid_feedfamily covid_medicalcare 
factor covid_rent covid_forego covid_feedfamily covid_medicalcare, pcf
ereturn list
rotate
estat kmo
predict factor1
rename factor1 covid_impacts

rename covid_stimulus stimulus
global covid "stimulus covid_impacts covid_lostjobhours covid_symptoms"

logit hhbill_month $demographics govassist_mo_binary $covid _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) asis
est store x

logit notice_month $demographics govassist_mo_binary $covid _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) asis
est store y

logit disconnect_month $demographics govassist_mo_binary $covid _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) asis
est store z

la var stimulus "COVID Stimulus"
la var covid_impacts "COVID Impacts"
la var covid_lostjobhours "COVID Lost Job Hours"
la var covid_symptoms "COVID Symptoms"


coefplot (x, label(Household Bill) msymbol(O)) (y, label(Received Notice) msymbol(T)) (z, label(Got Disconnected) msymbol(S)), title("Last Month") eform drop(_cons) xline(1) xtitle("Odds ratio") text(1.1 1.2, box fcolor(white) lcolor(black)) ysize(9) xsize(13) legend(pos(5) row(1)) keep($covid) graphregion(fcolor(white)) xlabel(0(1)8)


**********************************************************************Robustness checks*******************************************************************************

***last year but not last month COVID logits***
logit hhbill_justyear $demographics govassist_mo_binary stimulus covid_rent covid_forego covid_feedfamily covid_medicalcare covid_lostjobhours covid_symptoms [pweight=weight], vce(cl inputstate) asis

logit notice_justyear $demographics govassist_mo_binary stimulus covid_rent covid_forego covid_feedfamily covid_medicalcare covid_lostjobhours covid_symptoms [pweight=weight], vce(cl inputstate) asis

logit disconnect_justyear $demographics govassist_mo_binary stimulus covid_rent covid_forego covid_feedfamily covid_medicalcare covid_lostjobhours covid_symptoms [pweight=weight], vce(cl inputstate) asis

***Demographics OLS regressions year vs month****
global demographics "hh_under5 hh_disability unemployed electronic_device retired black hispanic female age under_100_fpl over_150_fpl educ home housing_conditions"


regress hhbill_year $demographics govassist_yr_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) 

regress notice_year_binary $demographics govassist_yr_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) 

regress disconnect_year_binary $demographics govassist_yr_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) 

regress hhbill_month $demographics govassist_mo_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) 

regress notice_month $demographics govassist_mo_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) 

regress disconnect_month $demographics govassist_mo_binary _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) 


***COVID OLS***
global covid "stimulus covid_impacts covid_lostjobhours covid_symptoms"

regress hhbill_month $demographics govassist_mo_binary $covid _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) 

regress notice_month $demographics govassist_mo_binary $covid _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) 

regress disconnect_month $demographics govassist_mo_binary $covid _Iinputstat_2-_Iinputstat_56 [pweight=weight], vce(cl inputstate) 
outreg2 using ${ao}\demographics_assist_covid_ols.rtf, keep(


****Last year but not last month COVID OLS***
regress hhbill_justyear $demographics govassist_mo_binary stimulus covid_rent covid_forego covid_feedfamily covid_medicalcare [pweight=weight], vce(cl inputstate) 

regress notice_justyear $demographics govassist_mo_binary stimulus covid_rent covid_forego covid_feedfamily covid_medicalcare [pweight=weight], vce(cl inputstate) 

regress disconnect_justyear $demographics govassist_mo_binary stimulus covid_rent covid_forego covid_feedfamily covid_medicalcare [pweight=weight], vce(cl inputstate) 